Skip to content

Conversation

SnirBroshi
Copy link
Contributor

@SnirBroshi SnirBroshi commented Oct 2, 2021

Fixes #1336 by adding an array option called "whitespaceOptions" to StreamWriterBuilder, and a possible value called "colonBraceSameLine" which causes { and [ following a colon to be placed in the same line.
The option is backed by a flag enum in BuiltStyledStreamWriter.

Example usage:

Json::StreamWriterBuilder builder;
builder.settings_["whitespaceOptions"] = Json::Value { Json::ValueType::arrayValue };
builder.settings_["whitespaceOptions"].append("colonBraceSameLine");

Json::Value json { Json::ValueType::objectValue };
json["hello"] = Json::Value { Json::ValueType::objectValue };
json["hello"]["world"] = "!";
json["world"] = Json::Value { Json::ValueType::arrayValue };
json["world"].append("!");

std::cout << Json::writeString(builder, json) << std::endl;

Result:

{
        "hello": {
                "world": "!"
        },
        "world": [
                "!"
        ]
}

@cdunn2001
Copy link
Contributor

I like this. Thanks. Could use a test though.

Does anyone else have time to review this?

@baylesj
Copy link
Contributor

baylesj commented Dec 15, 2021

I'd be happy to review once there is test coverage associated with this.

@SnirBroshi
Copy link
Contributor Author

Rebased and fixed review comment

@baylesj
Copy link
Contributor

baylesj commented Sep 12, 2024

This needs to be formatted and have tests added.

Closing this due to inactivity. Feel free to reopen if you are able to address feedback.

@baylesj baylesj closed this Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Braces/brackets on the same line

4 participants